package midi;

import inputs.Input;

import java.util.List;

import javax.sound.midi.Receiver;

import management.UpdateManager;
import dataModifiers.Average;
import dataModifiers.Modifier;
import dataModifiers.ModifierFactory;


/**
 * Singleton factory class for creating MidiOutParameters.
 * Creating MidiOutParameters through this class ensures they are added to the UpdateManager.
 * 
 * @author Dylan James
 *
 */
public class MidiOutParameterFactory {
	private static MidiOutParameterFactory instance;
	
	private static UpdateManager updateManager;
	
	private MidiOutParameterFactory()
	{
		updateManager = UpdateManager.getUpdateManager();
	}
	
	/**
	 * @return An instance of the MidiOut Parameter Factory.
	 */
	public static MidiOutParameterFactory getFactory()
	{
		if (instance == null)
		{
			instance = new MidiOutParameterFactory();
		}
		
		return instance;
	}
	
	
	/**
	 * Adds a MidiOutParameter to the update management
	 * @param midiOutParam MidiOutParameter to add
	 */
	private void Add(MidiOutParameter midiOutParam)
	{
		updateManager.Add(midiOutParam);
	}
	
	/**
	 * Creates a PitchVelocityMidiOutParameter and adds it to the Update Management if specified so it is written automatically each tick.
	 * @param pitch The Input to use for Pitch data.
	 * @param velocity The Input to use for Velocity data.
	 * @param rec The Midi Receiver to write to.
	 * @param channel The channel on the Midi Device to write to.
	 * @param update Whether this should be automatically written every tick.
	 * @return The created PitchVelocityMidiOutParameter
	 */
	public PitchVelocityMidiOutParameter createPitchVelocityMidiOutParameter(Input pitch, Input velocity, Receiver rec, int channel, boolean update)
	{
		PitchVelocityMidiOutParameter pvmop = new PitchVelocityMidiOutParameter(pitch, velocity, rec, channel);
		
		if (update)
		{
			Add(pvmop);
		}
		
		return pvmop;
	}
	
	/**
	 * Creates a PitchVelocityMidiOutParameter and automatically writes it every tick.
	 * @param pitch The Input to use for Pitch data.
	 * @param velocity The Input to use for Velocity data.
	 * @param rec The Midi Receiver to write to.
	 * @param channel The channel on the Midi Device to write to.
	 * @return The crated PitchVelocityMidiOutParameter
	 */
	public PitchVelocityMidiOutParameter createPitchVelocityMidiOutParameter(Input pitch, Input velocity, Receiver rec, int channel)
	{
		return createPitchVelocityMidiOutParameter(pitch, velocity, rec, channel, true);
	}
}
